﻿using System;
using System.Reflection;
using log4net;
using log4net.Config;
using MyNamespace;

namespace Log4net
{
    class Program
    {
        static void Main(string[] args)
        {
            //XmlConfigurator.Configure(); // or add some code to AssemblyInfo.cs file

            //var logger = new Logger();
            //logger.DoLog();
            
			//GlobalContext.Properties["UserName"] = User.Identity.Name;
            //GlobalContext.Properties["Source"] = "Server";
			
            var namedLogger = new MySecondClass();
            namedLogger.DoLog();
            Console.ReadLine();
            //Console.ReadLine();
        }
    }

    public class Logger
    {
        private readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public void DoLog()
        {
            var ex = new Exception();
            log.Error(ex.Message, ex);
            //log.Debug("Debug message");
            //log.Info("Info message");
            //log.Warn("Warn message");
            //log.Error("Error message");
            
        }
    }
}

namespace MyNamespace
{
    public class MySecondClass
    {
        private readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // "MyNamespace.MySecondClass"

        public void DoLog()
        {
            var a = new Exception();
            log.Error(a.Message, a);
            //log.Debug("Debug message");
            //log.Info("Info message");
            //log.Warn("Warn message");
            //log.Error("Error message");
        }
    }
}
